package com.gitee.wsl.android.ui.recyclerView.adapter

import android.content.Context
import android.view.View
import android.widget.TextView
import com.gitee.wsl.android.ui.recyclerView.adapter.viewholder.ViewHolderConfig

fun <T : Any,AR: com.gitee.wsl.android.ui.recyclerView.adapter.ActionRepository<T>> listAdapter(context:Context, configCallback:ListAdapterScope<T,AR>.()->Unit): ListBuilderAdapter<T,AR>{
    val builder=AdapterBuilder(context,configCallback = configCallback)
    return builder.buildListAdapter()
}

fun <T : Any> sampleListAdapter(context:Context,configCallback:ListAdapterScope<T, com.gitee.wsl.android.ui.recyclerView.adapter.ActionRepository<T>>.()->Unit): ListBuilderAdapter<T, com.gitee.wsl.android.ui.recyclerView.adapter.ActionRepository<T>>{
    val builder=AdapterBuilder(context,configCallback = configCallback)
    return builder.buildListAdapter()
}

fun <T : Any,AR: com.gitee.wsl.android.ui.recyclerView.adapter.ActionRepository<T>> pagingAdapter(context:Context, configCallback:PagingAdapterScope<T,AR>.()->Unit): PagingBuilderAdapter<T,AR>{
    val builder=AdapterBuilder(context,configCallback = configCallback)
    return builder.buildPagerAdapter()
}


fun <T : Any> samplePagingAdapter(context:Context,configCallback:PagingAdapterScope<T, com.gitee.wsl.android.ui.recyclerView.adapter.ActionRepository<T>>.()->Unit): PagingBuilderAdapter<T, com.gitee.wsl.android.ui.recyclerView.adapter.ActionRepository<T>>{
    val builder=AdapterBuilder(context,configCallback = configCallback)
    return builder.buildPagerAdapter()
}

/*
interface AdapterDslScope{

    //fun config(configScope:AdapterConfig.()->Unit)

    fun holder(holderScope:HolderDslScope)

}

interface HolderDslScope{

}


class AdapterDsl(scope:AdapterDslScope.()->Unit):AdapterDslScope {

    override fun holder(holderScope: HolderDslScope) {
        TODO("Not yet implemented")
    }

}*/



fun testAdapter(context: Context){
    listAdapter<Long, com.gitee.wsl.android.ui.recyclerView.adapter.Action.ClickAction<Long>>(context) {
       registerViewHolderFactory(0,android.R.layout.activity_list_item) {itemView: android.view.View, position: kotlin.Int, payloads: kotlin.collections.List<kotlin.Any>, item: kotlin.Long?, config: ViewHolderConfig<Long, Action.ClickAction<Long>> ->
           itemView.findViewById<TextView>(android.R.id.text1)
       }
       registerViewHolderFactory<TextView>{
           this.createBindView(android.R.layout.activity_list_item){
               TextView(this.context)
           }
           this.bindViewHolder { viewBinding, position, payloads, item, config ->
               viewBinding.text = item?.toString()
           }
       }
        itemTypeHandler { position, item, preItem, nextItem, layoutType ->
             0
        }
        registerActionRepository(object: Action.ClickAction<Long>{
            override fun onClick(v: View, position: Int, item: Long?) {

            }
        })
        sampleTitleHolder { holder, position, payloads, item, config ->
            holder.title.text="sample text"
            holder.title.setOnClickListener {
                config.repository?.onClick(it,position,item)
            }
            config.configViewActionState(config,holder.title,position)
        }

        this.registerViewHolderFactory(0,android.R.layout.activity_list_item){itemView: android.view.View, position: kotlin.Int, payloads: kotlin.collections.List<kotlin.Any>, item: kotlin.Long?, config: ViewHolderConfig<kotlin.Long, Action.ClickAction<kotlin.Long>> ->


        }

        actionStateConfig { viewHolderConfig, textview, position ->
            viewHolderConfig.configViewActionState(viewHolderConfig,textview,position)
        }

    }
}